home *** CD-ROM | disk | FTP | other *** search
- Path: janus.cqu.edu.au!usenet
- From: Mutchg@Topaz.Cqu.Edu.Au (G.D.Mutch)
- Newsgroups: comp.lang.c++
- Subject: Re: returning a pointer to a struct with a class function
- Date: 18 Apr 1996 23:26:17 GMT
- Organization: CQ University
- Message-ID: <4l6j2p$38c@janus.cqu.edu.au>
- References: <4l5r9c$25s@dunlop.cs.strath.ac.uk>
- NNTP-Posting-Host: 138.77.57.12
- X-Newsreader: WinVN 0.92.6+
-
- In article <4l5r9c$25s@dunlop.cs.strath.ac.uk>, jmccross@cs.strath.ac.uk (Joe McCrossan) says:
- >
- >Does anyone know how to set up a function within a class to return a pointer to a
- >struct ie
- >
- > struct tree_node *Rotate(char *, struct tree_node *);
- >
- >as I can't seem to get it to work.
- >
- >Any help would be greatly appreciated - please e-mail me.
- >
- >Thanks,
- >
- >Joe
-
- The function you have stated looks illogical ?
- You want a "Class" but you use a "Struct" this is ok but you loose
- meaningful understanding in your code.
-
-
- Try :
- class tree_node {
- private :
- int x,y
- tree_node *Return;
- .
- .
- .
- public :
- tree_node() {Return=0;} // constructor
- ~tree_nod() {delete Return[];} // destructor
-
- tree_node Rotate(char * , tree_node *return_val )
- {
- Return = new tree_node; // allocate the memory
- Return = return_val; // if you prefer
- }
-
- };//{eoc}
-
- Remember you pointer is lost with the final call to your routine or program.
-
- Common error is to point a variable to a delete data type.
-
- -Gm
-
-